﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>窗体滚动条随文字增加自动滚动</title>
    <script type="text/javascript">
        var txtMsg = "往右";                //要显示的文本
        //动态创建span标签
        var text = document.createElement("<span style=position:absolute;z-index:3;left:10px;top:10px></span>");
        var stat =true;
        function writeText()
        {
            text.innerText = txtMsg;        //显示文本
            txtMsg += "继续往右";           //连接文本内容
            div1.appendChild(text);         //将文本添加到div中
            window.setTimeout("writeText()",400);//设置定时器,不间断显示文本
            if (stat) {window.scrollTo(10000,0);}//主要控制滚动条的位置
        }
        document.onmousedown = function(){stat = false;}
    </script>
</head>
<body onload="writeText()">
<div id=div1 style=position:absolute;top:20px;left:20px;width:10000px;cursor:default>
</div>
</body>
</html>